package com.chookss.video

import android.graphics.Color
import android.view.View
import android.view.ViewGroup
import android.widget.BaseAdapter
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.TextView
import com.chookss.R
import com.chookss.tools.GlideUtils
import com.chookss.tools.Utils
import com.chookss.video.entity.VideoEntity

/**
 * Company:
 * Project:
 * Author: liuhaoge
 * Date: 2021/1/20 14:56
 * Note:
 */
class VideoInSetsAdapter : BaseAdapter() {
    var datas:List<VideoEntity>? = null
    var selectInt:Int? = 0
    set(value) {
        field = value
        notifyDataSetChanged()
    }

    override fun getCount() = datas?.size?:0

    override fun getItem(position: Int) = datas!![position]

    override fun getItemId(position: Int) = 0L

    override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
        var view = convertView ?: View.inflate(parent.context, R.layout.item_video_in_list, null)
        getItem(position).let {
            GlideUtils.load(parent.context,it.videoCoverPath,view.findViewById(R.id.ivCover),R.drawable.default_vedio)
            view.findViewById<TextView>(R.id.tvTitle).setText("第"+it.videoSort+"集 | "+it.videoTitle)
            view.findViewById<TextView>(R.id.tvTime).setText(Utils.changeTime(it.videoSeconds))
            view.findViewById<TextView>(R.id.tvZan).setText(it.videoLikeCounts.toString())
            if("0".equals(it.isLike)){
                view.findViewById<ImageView>(R.id.ivZan).setBackgroundResource(R.drawable.icon_like)
            }else{
                view.findViewById<ImageView>(R.id.ivZan).setBackgroundResource(R.drawable.icon_liked)
            }
            if(selectInt==position){
                view.findViewById<LinearLayout>(R.id.llContent).setBackgroundColor(Color.parseColor("#30ffffff"))
            }else{
                view.findViewById<LinearLayout>(R.id.llContent).setBackgroundColor(Color.parseColor("#00000000"))
            }
           if("1".equals(it.isTask)){
               if("1".equals(it.compeleteFlag)){
                   view.findViewById<TextView>(R.id.tvCompletee).visibility=View.VISIBLE
                   view.findViewById<TextView>(R.id.tvCompletee).text="已学完"
               }else{
                   view.findViewById<TextView>(R.id.tvCompletee).visibility=View.GONE
               }
           }else{
               view.findViewById<TextView>(R.id.tvCompletee).visibility=View.GONE
           }
        }
        if(position+1==datas?.size){
            view.findViewById<TextView>(R.id.tvNone).visibility=View.VISIBLE
        }else{
            view.findViewById<TextView>(R.id.tvNone).visibility=View.GONE
        }

        return view
    }

}